package com.xfp.controller;

import com.xfp.pojo.dto.NodeDto;
import com.xfp.pojo.dto.Region;
import com.xfp.pojo.dto.RegionDto;
import com.xfp.pojo.dto.RegionQueryDto;
import com.xfp.pojo.vo.RegionDetailedQueryVo;
import com.xfp.pojo.vo.RegionQueryVo;
import com.xfp.pojo.vo.RegionVo;
import com.xfp.result.Result;
import com.xfp.service.RegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service")
@Slf4j
@Api(tags = "区域管理")
public class RegionController {

    @Autowired
    private RegionService regionService;

    /**
     * 新增区域
     * @param dto
     * @return
     * @throws Exception
     */
    @PostMapping("/region")
    @ApiOperation("新增区域")
    public Result<Boolean> insertRegion(@RequestBody RegionDto dto) throws Exception {
        log.info("新增区域:{}", dto);
        regionService.insertRegion(dto);
        return Result.success(true);
    }

    /**
     * 修改区域
     * @param regionId
     * @param dto
     * @return
     * @throws Exception
     */
    @PutMapping("/region/{regionId}")
    @ApiOperation("修改区域")
    public Boolean udpateRegion(@PathVariable Long regionId,@RequestBody RegionDto dto) throws Exception {
        log.info("修改区域：{},{}",regionId,dto);
        regionService.updateRegion(regionId,dto);
        return true;
    }

    /**
     * 删除区域
     * @param regionId
     * @return
     * @throws Exception
     */
    @DeleteMapping("/region/{regionId}")
    @ApiOperation("删除区域")
    public Result<Boolean> delete(@PathVariable Long regionId) throws Exception {
        log.info("删除区域：{}",regionId);
        regionService.delete(regionId);
        return Result.success(true);
    }

    /**
     * 区域搜索
     * @param dto
     * @return
     */
    @GetMapping("/region/search")
    @ApiOperation("区域搜索")
    public RegionQueryVo pageRegion(RegionQueryDto dto) throws Exception {
        log.info("区域搜索：{}",dto);
        RegionQueryVo vo = regionService.pageRegion(dto);
        return vo;
    }

}
